import java.util.ArrayDeque;
import java.util.Scanner;

/**
 * 单词变换
 */
//邻接矩阵表示法
class Vertex {
    public int no;
    public String name;
    public int pre;

    public Vertex(int no, String name) {
        this.no = no;
        this.name = name;
        pre = -1;
    }
}

class Graph {
    public int edge[][] = new int[100][100];
    public int n;
    public int e;
    public Vertex[] vex = new Vertex[100];

    public boolean isBian(Vertex v1, Vertex v2) {
        int count = 0;
        for (int i = 0; i < v1.name.length(); i++) {
            if (v1.name.charAt(i) != v2.name.charAt(i)) {
                count++;
            }
        }
        if (count == 1)
            return true;
        else
            return false;
    }

    public int find(String d) {
        for (int i = 0; i < n; i++) {
            if (vex[i].name.equals(d))
                return i;
        }
        return -1;
    }

    public int createGraph(Scanner sc) {
        String s = sc.next();
        String d = sc.next();
        sc.nextLine();
        String s1 = sc.nextLine();
        String list = s + " " + s1;
        String[] word = list.split(" ");
        for (int i = 0; i < word.length; i++) {
            vex[i] = new Vertex(i, word[i]);
            n++;
        }
        for (int i = 0; i < word.length; i++)
            for (int j = 0; j < word.length; j++) {
                if (isBian(vex[i], vex[j])) {
                    edge[i][j] = 1;
                    e++;
                } else {
                    edge[i][j] = 100;
                }
            }
        e = e / 2;
        int index = find(d);
        return index;
    }
}

public class Main {
    // 广度遍历求最短路径
    public static int BFS(Graph g, Vertex v, Vertex v1) {
        boolean[] visited = new boolean[g.n];
        for (int i = 0; i < visited.length; i++)
            visited[i] = false;
        ArrayDeque<Vertex> q = new ArrayDeque<>();
        //System.out.println(v.name);
        visited[0] = true;
        q.offer(v);
        while (q.isEmpty() != true) {
            Vertex temp = q.poll();
            for (int i = 0; i < g.n; i++) {
                if (g.edge[temp.no][i] == 1 && !visited[i]) {
                    visited[i] = true;
                    // System.out.println(g.vex[i].name);
                    g.vex[i].pre = temp.no;
                    if (g.vex[i].name.equals(v1.name)) {
                        int count = 1;
                        while (g.vex[i].pre != -1) {
                            count++;
                            i = g.vex[i].pre;
                        }
                        return count;
                    }
                    q.offer(g.vex[i]);
                }
            }
        }
        return -1;
    }

    //迪杰斯特拉算法求最短路径
    public static void Dijkstra(Graph g, Vertex v, Vertex v1, int dist[], int path[]) {  //初始化操作
        int[] set = new int[g.n];
        int u = 0;
        for (int i = 0; i < g.n; i++) {
            dist[i] = g.edge[v.no][i];
            set[i] = 0;
            if (g.edge[v.no][i] < 100) {
                path[i] = v.no;
            } else {
                path[i] = -1;
            }
        }
        set[v.no] = 1;
        path[v.no] = -1;//初始化结束
        for (int i = 0; i < g.n; i++) {
            int min = 100;
            for (int j = 0; j < g.n; j++) {
                if (set[j] == 0 && dist[j] < min) {
                    u = j;
                    min = dist[j];
                }
            }
            set[u] = 1;
            for (int j = 0; j < g.n; j++) {
                if (set[j] == 0 && dist[u] + g.edge[u][j] < dist[j]) {
                    dist[j] = dist[u] + g.edge[u][j];
                    path[j] = u;
                }
            }

        }
        System.out.println(dist[v1.no] + 1);

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Graph g = new Graph();
            int index = g.createGraph(sc);
            Vertex v = g.vex[0];
            Vertex v1 = g.vex[index];
            int[] dist = new int[g.n];
            int[] path = new int[g.n];
            Dijkstra(g, v, v1, dist, path);
            //  System.out.println(BFS(g,v,v1));
       /* for(int i=0;i<g.n;i++)
        {   for(int j=0;j<g.n;j++)
                System.out.print(g.edge[i][j]+" ");
          System.out.println();
        }   */
        }
    }

}

//import java.util.ArrayList;
//import java.util.Scanner;
//
//public class Main {
//    static int[][] matrix;// 邻接矩阵
//    static int len;// 单词个数
//    static ArrayList<Integer> path;// 单条路径记录
//    static ArrayList<ArrayList<Integer>> paths;// 所有路径
//
//    public static void main(String[] args) {
//// 接收输入参数
//        Scanner scanner = new Scanner(System.in);
//        String init = scanner.nextLine();
//        String end = scanner.nextLine();
//        String list = scanner.nextLine();
//        scanner.close();
//        // 将所有单词存入数组
//        len = list.split(" ").length + 1;
//        String[] vocabulary = new String[len];
//        vocabulary[0] = init;
//        int start = 0; // 最终词所在的索引
//        for (int i = 1; i < len; i++) {
//            vocabulary[i] = list.split(" ")[i - 1];
//            if (vocabulary[i].equals(end)) {
//                start = i;
//            }
//        }
//        // 构建邻接矩阵
//        matrix = nearMatrix(vocabulary);
//        path = new ArrayList<Integer>();
//        paths = new ArrayList<ArrayList<Integer>>();        // 开始搜索
//        look(start);        // 寻找最短路径
//        int min = Integer.MAX_VALUE;
//        for (int i = 0; i < paths.size(); i++) {
//            int k = paths.get(i).size();
//            if (k < min && paths.get(i).get(k - 1) == 0) {
//                min = k;
//            }
//        }
//        System.out.println(min + 1);
//    }
//
//    public static void look(int start) {
//        for (int i = 0; i < len; i++) {
//            if (matrix[start][i] == 1 && !path.contains(i)) {
//                path.add(i);
//                if (i != 0) {
//                    look(i);
//                } else {
//                    break;
//                }
//            }
//        }        // 添加路径
//        paths.add(path);
//        path = new ArrayList<Integer>();
//        int length = paths.get(paths.size() - 1).size();
//        for (int i = 0; i < length - 1; i++) {
//            path.add(paths.get(paths.size() - 1).get(i));
//        }
//    }    // 构建邻接矩阵
//
//    public static int[][] nearMatrix(String[] vac) {
//        int[][] matrix = new int[vac.length][vac.length];
//        for (int i = 0; i < vac.length; i++) {
//            for (int j = 0; j < vac.length; j++) {
//                matrix[i][j] = compare(vac[i], vac[j]);
//            }
//        }
//        return matrix;
//    }    // 比较两个单词是否可变换
//
//    public static int compare(String s1, String s2) {
//        int k = 0;
//        for (int i = 0; i < s1.length(); i++) {
//            if ((s1.charAt(i) + "").compareTo((s2.charAt(i) + "")) != 0) {
//                k++;
//                if (k > 1) {
//                    return Integer.MAX_VALUE;
//                }
//            }
//        }
//        return k;
//    }
//}